using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for Cls_Sort
/// </summary>
public class Cls_Sort
{
    
	public Cls_Sort()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    public int GetSortColumnIndex(GridView gv , string SortField )
    {
        foreach (DataControlField field in gv.Columns )
        {
            if (field.SortExpression ==  SortField )
            {
                return gv.Columns.IndexOf(field);
            }
        }
        return -1;
    }

    public void AddSortImage(int columnIndex, GridViewRow headerRow , string SortDirection)
    {
        // Create the sorting image based on the sort direction.
        Image sortImage = new Image();
        
        if ( SortDirection .Equals("ASC"))
        {
            sortImage.ImageUrl = "~/images/asc.gif";
            sortImage.AlternateText = "Ascending Order";
        }
        else
        {
            sortImage.ImageUrl = "~/images/desc.gif";
            sortImage.AlternateText = "Descending Order";
        }
        // Add the image to the appropriate header cell.
        
        headerRow.Cells[columnIndex].Controls.Add(sortImage);
    }

}
